package org.corolla.cloth.web.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage(value = "struts-default")
@Results({
          @Result(name = "input", type = "redirect", location = "/view/StyleMan.jsp"),
          @Result(name = "success", type = "redirect", location = "/view/SizeChoose.jsp") })
@Namespace("/view")
@Action(value = "styleAction")
public class StyleAction extends ActionSupport {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String            styleName;
    private String            redioid;

    @Override
    public String execute() throws Exception {
        // 程序运行到execute()时，前面的验证都已经正确了
        boolean access = false;
        Date date = new Date();
        if (date.getHours()>21) {
            access = true;
        }
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
        session.setAttribute("style_name", this.getStyleName().substring(0,this.getStyleName().indexOf("_")));
        session.setAttribute("style_image", this.getStyleName().substring(this.getStyleName().indexOf("_")+1));
        session.setAttribute("redioid", this.getRedioid());
        if (StringUtils.isNotBlank(this.getStyleName()) && StringUtils.isNotBlank(this.getRedioid())) {
            return SUCCESS;
        }
        return "input";
    }

    public String getStyleName() {
        return styleName;
    }

    public void setStyleName(String styleName) {
        this.styleName = styleName;
    }

    public String getRedioid() {
        return redioid;
    }

    public void setRedioid(String redioid) {
        this.redioid = redioid;
    }

}
